package edu.csl.study.shardingsphere.health.controller;


import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import edu.csl.study.shardingsphere.health.entity.HealthRecord;
import edu.csl.study.shardingsphere.health.entity.User2;
import edu.csl.study.shardingsphere.health.service.IHealthRecordService;
import edu.csl.study.shardingsphere.health.service.IUser2Service;
import edu.csl.study.shardingsphere.health.vo.HealthRecordTaskVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.sql.SQLException;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 自动生成代码
 * @since 2022-05-19
 */
@RestController
@RequestMapping("/health/health-record")
public class HealthRecordController {

    @Autowired
    IHealthRecordService healthRecordService;

    @RequestMapping("/list")
    public List<HealthRecord> list() throws SQLException {

        return healthRecordService.list();
    }
    @RequestMapping("/insert")
    public String processUsers() throws SQLException {
        healthRecordService.processHealthRecords();
        return "insert SUCCESS";
    }

    @RequestMapping("/delete")
    public String deleteList() throws SQLException {
        healthRecordService.deleteAll();
        return "delete SUCCESS";
    }
    @RequestMapping("/update/{id}")
    public String update(@PathVariable("id") Long id) throws SQLException {

        UpdateWrapper<HealthRecord> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("record_id",id).set("remark", System.currentTimeMillis()+"");
        healthRecordService.update(updateWrapper);
        return "update SUCCESS";
    }

    @RequestMapping("/join/{type}/{id}")
    public List<HealthRecordTaskVo> join(@PathVariable("type") Integer type,@PathVariable("id") Long id) throws SQLException {

        return healthRecordService.getHealthRecordTaskVo(type, id);
    }

}
